/*
 * Created by JFormDesigner on Tue Oct 26 23:00:54 CST 2021
 */

package hpasUserInterfaces.itemQueryPage;

import hpasControllers.HardwareQueryController;
import hpasDAO.HardwareDAO;
import hpasDAO.HardwareItemDAO;
import hpasDAO.RetailerDAO;
import hpasDataEntities.Hardware;
import hpasUserInterfaces.userLoginPage.UserLogin;

import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.*;

/**
 * @author unknown
 */
public class HardwareQuery extends JFrame {
    private String title = "IT硬件报价系统 - GUEST (游客消费者) ";
    private HardwareQueryController controller;
    private ItemDetailWindow detailWindow;

    public HardwareQuery()
    {
        initComponents();
        addController();
        this.setTitle(title);
    }

    public HardwareQuery(String title)
    {
        this.title=title;
        initComponents();
        addController();
        this.setTitle(title);
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        tabbedPane7 = new JTabbedPane();
        panel1 = new JPanel();
        label1 = new JLabel();
        radioButton1 = new JRadioButton();
        radioButton3 = new JRadioButton();
        radioButton4 = new JRadioButton();
        radioButton5 = new JRadioButton();
        radioButton6 = new JRadioButton();
        radioButton2 = new JRadioButton();
        radioButton7 = new JRadioButton();
        radioButton8 = new JRadioButton();
        radioButton9 = new JRadioButton();
        radioButton10 = new JRadioButton();
        label2 = new JLabel();
        comboBox2 = new JComboBox<>();
        label3 = new JLabel();
        comboBox3 = new JComboBox<>();
        label4 = new JLabel();
        textField1 = new JTextField();
        button1 = new JButton();
        label5 = new JLabel();
        scrollPane1 = new JScrollPane();
        table1 = new JTable();
        label6 = new JLabel();
        button3 = new JButton();
        label7 = new JLabel();
        button4 = new JButton();
        label8 = new JLabel();
        panel2 = new JPanel();

        //======== this ========
        setTitle("IT\u786c\u4ef6\u62a5\u4ef7\u7cfb\u7edf - <username> (\u6d88\u8d39\u8005) ");
        setFont(new Font("\u5fae\u8f6f\u96c5\u9ed1", Font.PLAIN, 12));
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);
        Container contentPane = getContentPane();
        contentPane.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 20));

        //======== tabbedPane7 ========
        {
            tabbedPane7.setPreferredSize(new Dimension(800, 500));
            tabbedPane7.setFont(tabbedPane7.getFont().deriveFont(tabbedPane7.getFont().getSize() + 2f));

            //======== panel1 ========
            {
                panel1.setPreferredSize(new Dimension(1452, 31));
                panel1.setLayout(new FlowLayout(FlowLayout.LEFT));

                //---- label1 ----
                label1.setText("\u786c\u4ef6\u7c7b\u578b");
                label1.setPreferredSize(new Dimension(790, 20));
                label1.setFont(label1.getFont().deriveFont(label1.getFont().getSize() + 3f));
                panel1.add(label1);

                //---- radioButton1 ----
                radioButton1.setText("\u663e\u5361");
                radioButton1.setMaximumSize(new Dimension(43, 21));
                radioButton1.setPreferredSize(new Dimension(154, 30));
                radioButton1.setFont(radioButton1.getFont().deriveFont(radioButton1.getFont().getSize() + 2f));
                panel1.add(radioButton1);

                //---- radioButton3 ----
                radioButton3.setText("CPU");
                radioButton3.setPreferredSize(new Dimension(154, 21));
                radioButton3.setFont(radioButton3.getFont().deriveFont(radioButton3.getFont().getSize() + 2f));
                panel1.add(radioButton3);

                //---- radioButton4 ----
                radioButton4.setText("\u952e\u76d8");
                radioButton4.setPreferredSize(new Dimension(154, 21));
                radioButton4.setFont(radioButton4.getFont().deriveFont(radioButton4.getFont().getSize() + 2f));
                panel1.add(radioButton4);

                //---- radioButton5 ----
                radioButton5.setText("\u786c\u76d8");
                radioButton5.setPreferredSize(new Dimension(154, 21));
                radioButton5.setFont(radioButton5.getFont().deriveFont(radioButton5.getFont().getSize() + 2f));
                panel1.add(radioButton5);

                //---- radioButton6 ----
                radioButton6.setText("\u9f20\u6807");
                radioButton6.setPreferredSize(new Dimension(154, 21));
                radioButton6.setFont(radioButton6.getFont().deriveFont(radioButton6.getFont().getSize() + 2f));
                panel1.add(radioButton6);

                //---- radioButton2 ----
                radioButton2.setText("\u663e\u793a\u5668");
                radioButton2.setMaximumSize(new Dimension(43, 21));
                radioButton2.setPreferredSize(new Dimension(154, 30));
                radioButton2.setFont(radioButton2.getFont().deriveFont(radioButton2.getFont().getSize() + 2f));
                panel1.add(radioButton2);

                //---- radioButton7 ----
                radioButton7.setText("\u7b14\u8bb0\u672c");
                radioButton7.setPreferredSize(new Dimension(154, 21));
                radioButton7.setFont(radioButton7.getFont().deriveFont(radioButton7.getFont().getSize() + 2f));
                panel1.add(radioButton7);

                //---- radioButton8 ----
                radioButton8.setText("\u4e00\u4f53\u673a");
                radioButton8.setPreferredSize(new Dimension(154, 21));
                radioButton8.setFont(radioButton8.getFont().deriveFont(radioButton8.getFont().getSize() + 2f));
                panel1.add(radioButton8);

                //---- radioButton9 ----
                radioButton9.setText("\u6563\u70ed\u5668");
                radioButton9.setPreferredSize(new Dimension(154, 21));
                radioButton9.setFont(radioButton9.getFont().deriveFont(radioButton9.getFont().getSize() + 2f));
                panel1.add(radioButton9);

                //---- radioButton10 ----
                radioButton10.setText("\u4e3b\u673a");
                radioButton10.setPreferredSize(new Dimension(154, 21));
                radioButton10.setFont(radioButton10.getFont().deriveFont(radioButton10.getFont().getSize() + 2f));
                panel1.add(radioButton10);

                //---- label2 ----
                label2.setText("\u7ec6\u5206\u7c7b\u578b");
                label2.setPreferredSize(new Dimension(80, 30));
                label2.setFont(label2.getFont().deriveFont(label2.getFont().getSize() + 2f));
                panel1.add(label2);

                //---- comboBox2 ----
                comboBox2.setPreferredSize(new Dimension(307, 30));
                comboBox2.setOpaque(false);
                comboBox2.setModel(new DefaultComboBoxModel<>(new String[] {
                    "SSD",
                    "HDD",
                    "SSHG"
                }));
                panel1.add(comboBox2);

                //---- label3 ----
                label3.setText("\u786c\u4ef6\u54c1\u724c");
                label3.setPreferredSize(new Dimension(80, 20));
                label3.setFont(label3.getFont().deriveFont(label3.getFont().getSize() + 2f));
                panel1.add(label3);

                //---- comboBox3 ----
                comboBox3.setPreferredSize(new Dimension(307, 30));
                comboBox3.setModel(new DefaultComboBoxModel<>(new String[] {
                    "\u4e09\u661f",
                    "\u897f\u90e8\u6570\u636e",
                    "\u5e0c\u6377"
                }));
                panel1.add(comboBox3);

                //---- label4 ----
                label4.setText("\u68c0\u7d22\u5173\u952e\u5b57");
                label4.setPreferredSize(new Dimension(80, 30));
                label4.setFont(label4.getFont().deriveFont(label4.getFont().getSize() + 2f));
                panel1.add(label4);

                //---- textField1 ----
                textField1.setPreferredSize(new Dimension(610, 30));
                panel1.add(textField1);

                //---- button1 ----
                button1.setText("\u641c\u7d22");
                button1.setPreferredSize(new Dimension(90, 30));
                button1.setFont(button1.getFont().deriveFont(button1.getFont().getSize() + 2f));
                panel1.add(button1);

                //---- label5 ----
                label5.setText("\u67091053\u4e2a\u5546\u5bb6\u5bf9\u8be5\u7c7b\u578b\u786c\u4ef6\u4f5c\u51fa\u62a5\u4ef7\uff08\u8fd1\u4e00\u5468\u5185\uff09\uff0c\u5747\u4ef7\u4e3a\uff1a");
                label5.setPreferredSize(new Dimension(790, 17));
                label5.setFont(label5.getFont().deriveFont(label5.getFont().getSize() + 2f));
                panel1.add(label5);

                //======== scrollPane1 ========
                {

                    //---- table1 ----
                    table1.setPreferredScrollableViewportSize(new Dimension(790, 200));
                    table1.setRowMargin(2);
                    table1.setModel(new DefaultTableModel(
                        new Object[][] {
                            {"", null, null, null, null, null},
                            {null, null, null, null, null, null},
                            {null, null, null, null, null, null},
                            {null, null, null, null, null, null},
                            {null, null, null, null, null, null},
                            {null, null, null, null, null, null},
                            {null, null, null, null, null, null},
                        },
                        new String[] {
                            "\u5546\u54c1\u540d", "\u578b\u53f7", "\u5546\u5bb6\u540d", "\u4ef7\u683c", "\u5730\u5740", "\u8054\u7cfb\u65b9\u5f0f/\u6e20\u9053"
                        }
                    ));
                    scrollPane1.setViewportView(table1);
                }
                panel1.add(scrollPane1);

                //---- label6 ----
                label6.setPreferredSize(new Dimension(205, 17));
                panel1.add(label6);

                //---- button3 ----
                button3.setText("\u67e5\u770b");
                panel1.add(button3);

                //---- label7 ----
                label7.setPreferredSize(new Dimension(205, 17));
                panel1.add(label7);

                //---- button4 ----
                button4.setText("\u8bc4\u8bba");
                panel1.add(button4);

                //---- label8 ----
                label8.setPreferredSize(new Dimension(205, 17));
                panel1.add(label8);
            }
            tabbedPane7.addTab("\u786c\u4ef6\u4ef7\u683c\u67e5\u8be2", panel1);

            //======== panel2 ========
            {
                panel2.setLayout(new FlowLayout());
            }
            tabbedPane7.addTab("\u8bc4\u8bba", panel2);
        }
        contentPane.add(tabbedPane7);
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
        group=new ButtonGroup();

        group.add(radioButton1);
        group.add(radioButton3);
        group.add(radioButton4);
        group.add(radioButton5);
        group.add(radioButton6);
        group.add(radioButton2);
        group.add(radioButton7);
        group.add(radioButton8);
        group.add(radioButton9);
        group.add(radioButton10);

    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JTabbedPane tabbedPane7;
    private JPanel panel1;
    private JLabel label1;
    private JRadioButton radioButton1;
    private JRadioButton radioButton3;
    private JRadioButton radioButton4;
    private JRadioButton radioButton5;
    private JRadioButton radioButton6;
    private JRadioButton radioButton2;
    private JRadioButton radioButton7;
    private JRadioButton radioButton8;
    private JRadioButton radioButton9;
    private JRadioButton radioButton10;
    private JLabel label2;
    private JComboBox<String> comboBox2;
    private JLabel label3;
    private JComboBox<String> comboBox3;
    private JLabel label4;
    private JTextField textField1;
    private JButton button1;
    private JLabel label5;
    private JScrollPane scrollPane1;
    private JTable table1;
    private JLabel label6;
    private JButton button3;
    private JLabel label7;
    private JButton button4;
    private JLabel label8;
    private JPanel panel2;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
    private ButtonGroup group;

    private void addController()
    {
        controller = new HardwareQueryController();
        controller.setHardwareDAO(new HardwareDAO());
        controller.setHardwareItemDAO(new HardwareItemDAO());
        controller.setRetailerDAO(new RetailerDAO());
        controller.setKeyword(textField1);
        controller.setResultCaption(label5);
        controller.setResultBox(table1);
        controller.setSearch(button1);
        controller.setView(button3);
        controller.setDetailWindow(detailWindow);
        textField1.addActionListener(controller);
        button1.addActionListener(controller);
        button3.addActionListener(controller);
        this.addWindowListener(new WindowListener()
        {
            @Override
            public void windowOpened(WindowEvent e)
            {

            }

            @Override
            public void windowClosing(WindowEvent e)
            {
                UserLogin loginUI = new UserLogin();
                loginUI.setVisible(true);
            }

            @Override
            public void windowClosed(WindowEvent e)
            {

            }

            @Override
            public void windowIconified(WindowEvent e)
            {

            }

            @Override
            public void windowDeiconified(WindowEvent e)
            {

            }

            @Override
            public void windowActivated(WindowEvent e)
            {

            }

            @Override
            public void windowDeactivated(WindowEvent e)
            {

            }
        });
    }
}
